package com.apache.funds.service.pluginsTimeTask;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.api.TimeTaskService;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.funds.common.FundsUtil;

/**
 * 定时器：资金日终结果设置（期初+发生）统计汇总<br/>
 * （每日23点~24点之间执行，汇总当日各个用户轧差余额值到余额表，保证下一日可查询到余额）
 * @author Administrator
 *
 */
public class FundsTimeTaskBalancePlugin implements TimeTaskService, PluginConnector {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public boolean run() {
		logger.info("--------------------定时器：资金日终结果设置（期初+发生）开始--------------------");

		try {
			ResultEntity entity = (ResultEntity) FundsUtil.doFundsTimeTaskBalance(null);
			logger.info("操作结果：" + JSONObject.fromObject(entity));
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}

		logger.info("--------------------定时器：资金日终结果设置（期初+发生）结束--------------------");
		return false;
	}

	@Override
	public Object execute(ParamsVo arg0) throws Exception {
		// TODO Auto-generated method stub
		boolean f = run();
		ResultEntity entity = new ResultEntity();
		if (f) {
			entity.setResult("true");
			entity.setMessage("执行中成功");
		}else {
			entity.setResult("false");
			entity.setMessage("执行中失败");
		}
		return entity; 
	}

}
